#pragma once

#include "dfize.h"

class CRegionSceneNode;
struct SResource;

struct SSettings
{
	SSettings(dimension2d<u32> resolution = dimension2d<u32>(1024, 768), bool fullscreen = false)
		: Resolution(resolution), Fullscreen(fullscreen)
	{
	}

	dimension2d<u32> Resolution;
	bool Fullscreen;
};

class CSettings
{
public:
	CSettings(std::string file, CRegionSceneNode *region, std::string defaultfile);
	~CSettings();

	SMaterial readMaterial(std::string name, IVideoDriver *video) const;

	SResource* readResource(std::string name, ISceneManager *mgr) const;
	void readResources(ISceneManager *mgr, list<SResource*> &resources) const;

	SSettings readSettings() const;

	std::string readSetting(std::string name, std::string defaultvalue = "", array<std::string> *outdata = 0) const;
	int readSetting(std::string name, int defaultvalue, array<std::string> *outdata = 0) const;
	f32 readSetting(std::string name, f32 defaultvalue, array<std::string> *outdata = 0) const;

	static void readDfMaterials(std::string file, std::string type, std::map<std::string, DFHack::t_matgloss> &outmaterials);

	static bool fileExists(std::string name);
	static int getFileSize(std::string name);

	static std::string getStringFromTileClass(int tileclass);
	static int getTileClassFromString(std::string tileclass);

	static std::string getNameFromBuildingType(u32 buildingtype);

	static bool nextElem(char **buf, std::string &elem, array<std::string> &outdata);
	static bool parseData(char *buf, std::string &elem, array<std::string> &outdata);
	static vector3df readVector(array<std::string> &data);

private:
	bool readFile(std::string name, char *buf, int &buflen) const;

	bool findData(char *buf, const char *elem, array<std::string> &outdata) const;

	char *Buffer;
	int BufferSize;

	CRegionSceneNode *Region;
};